﻿#include "coladdlookdialog.h"
#include "ui_coladdlookdialog.h"
#include <QSqlQuery>

int COLaddlookDialog::AID;
COLaddlookDialog::COLaddlookDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::COLaddlookDialog)
{
    ui->setupUi(this);
    showpolitics();
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("添加信息状态：");
    connect(ui->cancelbtn,SIGNAL(clicked(bool)),this,SLOT(close()));
}


COLaddlookDialog::~COLaddlookDialog()
{
    delete ui;}

void COLaddlookDialog::receiveApprovalID(int ID)
{AID=ID;}

void COLaddlookDialog::on_ackbtn_clicked()
{
    if(ui->unit->text().isEmpty()||ui->read->text().isEmpty()){
        ui->status->setText("添加信息状态:请至少添入阅档人，阅档人单位");
   }
    else {
    QSqlQuery q;
    q.prepare("INSERT INTO ReadMen(ReadID,Readman,Readunit,Readduty,politicstatus,ApprovalID) "
              "VALUES(:ReadID,:Readman,:Readunit,:Readduty,:politicstatus,:ApprovalID)");
    q.bindValue(":Readman",ui->read->text());
    q.bindValue(":Readunit",ui->unit->text());
    q.bindValue(":Readduty",ui->duty->text());
    q.bindValue(":politicstatus",ui->politic->currentText());
    q.bindValue(":ApprovalID",AID);
    bool ok=q.exec();
    if(ok)
    {ui->status->setText("添加信息状态:添加成功");
            this->close();}
    else
    {ui->status->setText("添加信息状态:添加失败");}
}
}

void COLaddlookDialog::showpolitics()
{
    ui->politic->addItem("");
    QString judge=QString("select Politic from ZZB.PoliticCode ");
    QSqlQuery query;
    query.exec(judge);
    while(query.next())
    {
        QString z=query.value(0).toString();
        ui->politic->addItem(z);
}}
